package com.training.java.core.collections.car.post15;

import java.util.HashSet;
import java.util.Set;

import com.training.java.core.collections.car.pre15.Car;

public class CarHashSetDemo {

	public static void main(String[] args) {
		Car car1 = new Car("Toyota", "Corolla", 2010);
		Car car2 = new Car("Honda", "CRV", 2012);
		Car car3 = new Car("Ford", "focus", 2007);
		// Car car4= new Car();
		Car car5 = new Car("Honda", "CRV", 2012);
		// Car car5 = new Car("Honda","cRV",2013);

		car1.setPrice(17999.99);
		car2.setPrice(24999.99);
		car3.setPrice(19999.99);
		car5.setPrice(24999.99);

		Set<Car> setOfCars = new HashSet<Car>();

		setOfCars.add(car1);// here reference to car1 is same so overridden
							// equals method
		setOfCars.add(car1);// will check the equality for make and model which
							// is same here.

		setOfCars.add(car2); // here references for car2 and car5 are different
		setOfCars.add(car5);// But it is showing in the set. why?????

		setOfCars.add(car3);
		// setOfCars.add(car4);

		for (Car car : setOfCars) {
			System.out.println("Make:  " + car.getMake());
			System.out.println("Model: " + car.getModel());
			System.out.println("Year: " + car.getYear());
			System.out.println("Price: " + car.getPrice());
			System.out.println("************");

		}
		System.out.println("car 2 and car 5 are equal: " + car2.equals(car5));

	}

}
